package com.gopay.bis.service.bank.task;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gopay.bis.service.bank.TpasOrderService;
import com.gopay.common.constants.txncd.IntTxnCd;
import com.gopay.common.domain.bank.tpas.TpasMessage;
import com.gopay.common.domain.bank.tpas.TpasResult;
import com.gopay.remote.bank.TpasChargeInteractRemoteService;

public class TpasChargeTaskThread implements Runnable {

	private static Logger logger = LoggerFactory.getLogger(ExPayTaskThread.class);

	private TpasMessage tpasMsg;
	private TpasChargeInteractRemoteService bankService;
	private TpasOrderService tpasOrderService;

	public TpasChargeTaskThread(TpasMessage msg, TpasChargeInteractRemoteService bankService, TpasOrderService tpasOrderService) {
		this.tpasMsg = msg;
		this.bankService = bankService;
		this.tpasOrderService = tpasOrderService;
	}

	public void run() {
		TpasResult res = null;
		String transType = tpasMsg.getTransType();
		try {
			if(StringUtils.equals(transType, IntTxnCd._01611.value))
				res = bankService.mobileCharge(tpasMsg);
			else if(StringUtils.equals(transType, IntTxnCd._01612.value))
				res = bankService.flowCharge(tpasMsg);
			else if(StringUtils.equals(transType, IntTxnCd._01613.value))
				res = bankService.oilCardCharge(tpasMsg);
			else{
				logger.error("不支持的交易类型 ：" + transType);
			}
	        String amount = ((TpasMessage)res.getDefaultModel()).getAmount() + "";
	        int a = tpasOrderService.saveCpDebitAmount(tpasMsg.getOrderId(), amount);
		} catch (Exception e) {
			logger.error("TpasChargeTaskThread error", e);
		}
	}
}
